﻿using System;
using System.ServiceModel;
using Microsoft.Practices.Unity;

namespace DevWeb.Biztalk.DeploymentSettings.DeploymentService
{
    public class UnityServiceHost : ServiceHost
    {
        internal UnityContainer Container;


        public UnityServiceHost(UnityContainer container, Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
            if (container == null) throw new ArgumentNullException("container");

            var contracts = ImplementedContracts.Values;

            foreach (var c in contracts)
            {
                var instanceProvider = new UnityInstanceProvider(container, serviceType);

                c.Behaviors.Add(instanceProvider);
            }

            Container = container;
        }
    }
}